home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue29 / s3demo / S3DEMO.ZIP / Scripts.ZIP / CScript.txt next >
Encoding:
Text File  |  1997-11-19  |  13.4 KB  |  271 lines

  1. /*
  2.  * TSyntaxMemoParser Script
  3.  * ------------------------
  4.  *
  5.  * Author  :          David Brock
  6.  * Date    :          October 18 1997
  7.  * Language:          ANSI C
  8.  */
  9.  
  10. //--------------------------------------------------------------------------------------------------------------------
  11. //
  12. //
  13. //
  14. // Macro definitions. Parameters may be specified and the replacement text terminates with the end of
  15. // line (watch trailing blanks).
  16. //
  17. #define ct_DEFAULT                  0
  18. #define ct_COMMENT_LINE             1
  19. #define ct_COMMENT_STAR             2
  20. #define ct_IDENTIFIER               3
  21. #define ct_STRING                   4
  22. #define ct_NUMBER                   5
  23. #define ct_COMMENT                  6
  24. #define ct_OPERATOR                 7
  25. #define ct_RESERVED                 8
  26. #define ct_CHAR                     9
  27. #define ct_DIRECTIVE                10
  28. #define ct_MISC                     11
  29. #define ct_KEYWORD                  12
  30. #define ct_HEXNUMBER                13
  31.  
  32. #define _non_alpha_                 '[^_A-Za-z0-9]'
  33. #define _all_chars_                 '[\x00-\xFF]'
  34. #define _no_chars_                  '[]'
  35. #define _dont_care_                 _all_chars_
  36. #define _DEFAULT_BACKGROUND         clWhite
  37. #define _DEFAULT_FOREGROUND         clBlack
  38.  
  39.  
  40.  
  41. //--------------------------------------------------------------------------------------------------------------------
  42. //
  43. // %%language section
  44. //
  45. // Header section. Describes the textual name of the language, case sensitivity and options used by the language.
  46. //
  47. %%language
  48. Name                      = 'ANSI C'
  49. Case                      = __SENSITIVE
  50. Options                   = __DEFAULT_OPTIONS
  51. WordWrapColumn            = _EDGE
  52. Gutter                    = _DEFAULT_GUTTER
  53. Anchor                    = _DEFAULT_START_ANCHOR
  54. ExampleText               = '/* Comment */\n\
  55.                             \#include <stdio.h>\n\
  56.                             \char *documentation[] = {\n\
  57.                             \     "String text\\n"}\n\
  58.                             \a >> 2 > 3 ? 4 ? 5\n'
  59.  
  60. EditableStyles              ('Comment',       ct_COMMENT),
  61.                             ('String',        ct_STRING),
  62.                             ('Reserved word', ct_KEYWORD),
  63.                             ('Operator',      ct_MISC),
  64.                             ('Identifier',    ct_IDENTIFIER),
  65.                             ('Directive',     ct_DIRECTIVE),
  66.                             ('Number',        ct_NUMBER),
  67.                             ('Default',       ct_DEFAULT)
  68.  
  69.  
  70.  
  71.  
  72. //--------------------------------------------------------------------------------------------------------------------
  73. //
  74. // %%words section
  75. //
  76. // Used to specify simple languge keywords. These are constant value lexemes that always contain the same characters
  77. // and only require the end style to be specified. The words present here will always be tried first. If they fail
  78. // then the entries in the %%tokens section will be allowed to try a match.
  79. //
  80. // %%words table entries have 3 columns:
  81. //     Column 1          Quoted string giving the characters that make up the word
  82. //     Column 2          Quoted string that specifies how the word is terminated
  83. //     Column 3          Token value returned when word is recognised
  84. //
  85. %%words
  86. '++'                    _dont_care_               ct_OPERATOR
  87. '--'                    _dont_care_               ct_OPERATOR
  88. '+'                     _dont_care_               ct_OPERATOR
  89. '-'                     _dont_care_               ct_OPERATOR
  90. '*'                     _dont_care_               ct_OPERATOR
  91. '/'                     _dont_care_               ct_OPERATOR
  92. '&'                     _dont_care_               ct_OPERATOR
  93. '!'                     _dont_care_               ct_OPERATOR
  94. '~'                     _dont_care_               ct_OPERATOR
  95. '%'                     _dont_care_               ct_OPERATOR
  96. '>'                     _dont_care_               ct_OPERATOR
  97. '<'                     _dont_care_               ct_OPERATOR
  98. '>>'                    _dont_care_               ct_OPERATOR
  99. '<<'                    _dont_care_               ct_OPERATOR
  100. '>='                    _dont_care_               ct_OPERATOR
  101. '<='                    _dont_care_               ct_OPERATOR
  102. '=='                    _dont_care_               ct_OPERATOR
  103. '='                     _dont_care_               ct_OPERATOR
  104. '!='                    _dont_care_               ct_OPERATOR
  105. '^'                     _dont_care_               ct_OPERATOR
  106. '|'                     _dont_care_               ct_OPERATOR
  107. '&&'                    _dont_care_               ct_OPERATOR
  108. '||'                    _dont_care_               ct_OPERATOR
  109. '?'                     _dont_care_               ct_OPERATOR
  110. ':'                     _dont_care_               ct_OPERATOR
  111. '+='                    _dont_care_               ct_OPERATOR
  112. '-='                    _dont_care_               ct_OPERATOR
  113. '*='                    _dont_care_               ct_OPERATOR
  114. '/='                    _dont_care_               ct_OPERATOR
  115. '%='                    _dont_care_               ct_OPERATOR
  116. '>>='                   _dont_care_               ct_OPERATOR
  117. '<<='                   _dont_care_               ct_OPERATOR
  118. '&='                    _dont_care_               ct_OPERATOR
  119. '^='                    _dont_care_               ct_OPERATOR
  120. '|='                    _dont_care_               ct_OPERATOR
  121. ';'                     _dont_care_               ct_MISC
  122. '('                     _dont_care_               ct_MISC
  123. ')'                     _dont_care_               ct_MISC
  124. '['                     _dont_care_               ct_MISC
  125. ']'                     _dont_care_               ct_MISC
  126. '{'                     _dont_care_               ct_MISC
  127. '}'                     _dont_care_               ct_MISC
  128. //'"'                   _dont_care_               ct_STRING
  129. //'\''                  _dont_care_               ct_CHAR
  130. '\/*'                   _dont_care_               ct_COMMENT_STAR
  131. '\/\/'                  _dont_care_               ct_COMMENT_LINE
  132. '#'                     _dont_care_               ct_DIRECTIVE
  133. '0'                     '[xX]'                    ct_HEXNUMBER
  134. 'auto'                  _non_alpha_               ct_KEYWORD
  135. 'break'                 _non_alpha_               ct_KEYWORD
  136. 'case'                  _non_alpha_               ct_KEYWORD
  137. 'char'                  _non_alpha_               ct_KEYWORD
  138. 'continue'              _non_alpha_               ct_KEYWORD
  139. 'default'               _non_alpha_               ct_KEYWORD
  140. 'do'                    _non_alpha_               ct_KEYWORD
  141. 'double'                _non_alpha_               ct_KEYWORD
  142. 'else'                  _non_alpha_               ct_KEYWORD
  143. 'entry'                 _non_alpha_               ct_KEYWORD
  144. 'extern'                _non_alpha_               ct_KEYWORD
  145. 'float'                 _non_alpha_               ct_KEYWORD
  146. 'for'                   _non_alpha_               ct_KEYWORD
  147. 'goto'                  _non_alpha_               ct_KEYWORD
  148. 'if'                    _non_alpha_               ct_KEYWORD
  149. 'int'                   _non_alpha_               ct_KEYWORD
  150. 'long'                  _non_alpha_               ct_KEYWORD
  151. 'register'              _non_alpha_               ct_KEYWORD
  152. 'return'                _non_alpha_               ct_KEYWORD
  153. 'short'                 _non_alpha_               ct_KEYWORD
  154. 'sizeof'                _non_alpha_               ct_KEYWORD
  155. 'static'                _non_alpha_               ct_KEYWORD
  156. 'struct'                _non_alpha_               ct_KEYWORD
  157. 'switch'                _non_alpha_               ct_KEYWORD
  158. 'typedef'               _non_alpha_               ct_KEYWORD
  159. 'union'                 _non_alpha_               ct_KEYWORD
  160. 'unsigned'              _non_alpha_               ct_KEYWORD
  161. 'while'                 _non_alpha_               ct_KEYWORD
  162.  
  163.  
  164.  
  165.  
  166. //--------------------------------------------------------------------------------------------------------------------
  167. //
  168. // %%handler section
  169. //
  170. // The %%handler section gives rules to be applied once an entry in the %%words table has been recognised. Normally
  171. // no further processing is required but sometimes a token starts with a fixed set of characters but may be followed
  172. // by a character class rather than a known sequence.
  173. //
  174. // %%handler table entries have 4 columns:
  175. //     Column 1          Token value to be processed
  176. //     Column 2          Character specifier that follows recognised word
  177. //     Column 3          Quoted string specifying end sequence
  178. //     Column 4          Whether end sequence is part of lexeme
  179. //
  180. // The <character specifier> is defined as:
  181. //     Column 2          A single character specifier or pre-defined system character macro:
  182. //                         _PASCAL_CHAR         Pascal style character specifier
  183. //                         _C_CHAR              C style character specifier
  184. //                       If the lexeme can optionally have these characters then append '?' to the end
  185. //                       of the quoted string.
  186. //     Column 3          Up to 2 characters may be given as a sequence to terminate the lexeme.
  187. //                       Characters are specified using a simplified regular expression. If this
  188. //                       string is empty then the lexeme will never be matched.
  189. //
  190. %%handler
  191. ct_COMMENT_LINE         '[^\n]'?                    '\n'           _discard_
  192. ct_COMMENT_STAR         _all_chars_?                '*\/'          _use_
  193. ct_DIRECTIVE            '[^\n]'?                    '\n'           _discard_
  194. ct_HEXNUMBER            '[xX0-9A-Fa-f]'             '[^0-9a-fA-F]' _discard_
  195.  
  196. //--------------------------------------------------------------------------------------------------------------------
  197. //
  198. // %%tokens section
  199. //
  200. // Used to specify how to recognise non-fixed lexemes. Non-fixed lexemes are only tried if the table entries in the
  201. // %%words section have failed. The non-fixed lexeme is defiened by 5 columns as below:
  202. //     Column 1          Token value
  203. //     Column 2          Single start character specifier
  204. //     Column 3          Single contains character specifier
  205. //     Column 4          End sequence specifier
  206. //     Column 5          Whether end sequence is part of lexeme
  207. // Pre-defined token styles are implemented. If used they should be specified in Column 2. The implemented ones
  208. // are:
  209. //  __STD_PASCALSTRING   Pascal string -- starts with ' ands with ' and uses '' to represent
  210. //                       ' within a string. Does not extend beywond end of line.
  211. //  __STD_IDENTIFIER     Standard identifier. Starts with [_a-zA-Z], contains [_a-zA-Z0-9] and ends with
  212. //                       a non-alpha numeric character that is not part of the lexeme
  213. //  __STD_NUMBER_OR_FP   Integer or floating point constant of syntax:
  214. //                           <Digit String> [ '.' <Digit string> ] [ e|E [+-] <Digit string> ]
  215. //
  216. %%tokens
  217. ct_STRING               __STD_C_STRING
  218. ct_CHAR                 __STD_C_CHAR
  219. ct_IDENTIFIER           __STD_IDENTIFIER
  220. ct_NUMBER               __STD_NUMBER_OR_FP
  221.  
  222. //--------------------------------------------------------------------------------------------------------------------
  223. //
  224. // %%effects section
  225. //
  226. // Used to specify the default colors and font styles used for each token
  227. //
  228. //     Column 1          Token value
  229. //     Column 2          Font styles
  230. //     Column 3          Foreground color
  231. //     Column 4          Background color
  232. //     Column 5          Optional column specifying whether map entry is a 'hotspot'
  233. //
  234. // Columns 1-4 must be completed for all rows, Column 5 defaults to non-hotspot.
  235. //
  236. %%effects
  237. ct_DEFAULT              []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  238. ct_IDENTIFIER           []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  239. ct_STRING               [fsItalic]                  _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  240. ct_COMMENT              [fsItalic]                  clBlue                      _DEFAULT_BACKGROUND
  241. ct_KEYWORD              [fsBold]                    _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  242. ct_NUMBER               []                          clRed                       _DEFAULT_BACKGROUND
  243. ct_DIRECTIVE            []                          clGreen                     _DEFAULT_BACKGROUND
  244. ct_MISC                 []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
  245.  
  246.  
  247.  
  248. //--------------------------------------------------------------------------------------------------------------------
  249. //
  250. // %%map section
  251. //
  252. // Used to specify which entry in the %%effects table each token value uses. By default all token values map onto
  253. // __DEFAULT_TOKEN which is defined as zero. Table has 2 columns:
  254. //     Column 1          Recognised token value
  255. //     Column 2          Map table entry (i.e. %%effects table entry)
  256. // Normally the %%map table consists of identical value entries.
  257. %%map
  258. ct_IDENTIFIER           ct_IDENTIFIER
  259. ct_STRING               ct_STRING
  260. ct_NUMBER               ct_NUMBER
  261. ct_COMMENT              ct_COMMENT
  262. ct_COMMENT_LINE         ct_COMMENT
  263. ct_COMMENT_STAR         ct_COMMENT
  264. ct_KEYWORD              ct_KEYWORD
  265. ct_MISC                 ct_MISC
  266. ct_DIRECTIVE            ct_DIRECTIVE
  267. ct_CHAR                 ct_STRING
  268. ct_OPERATOR             ct_MISC
  269. ct_HEXNUMBER            ct_NUMBER
  270.  
  271.